home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 August / August CD.bin / Shareware / Education / numericalmethods Folder / chap_11 / a11_qr.m < prev    next >
Encoding:
Text File  |  1994-06-05  |  1.4 KB  |  55 lines  |  [MATS/MATL]

  1. echo off;
  2. % NUMERICAL METHODS: MATLAB Programs, (c) John H. Mathews 1994
  3. % To accompany the text:
  4. % NUMERICAL METHODS for Mathematics, Science and Engineering, 2nd Ed, 1992
  5. % Prentice Hall, Englewood Cliffs, New Jersey, 07632, U.S.A.
  6. % This free software is complements of the author.
  7.  
  8. % Algorithm 11.QR (Householder Reduction to Tridiagonal Form).
  9. %                 (Followed by the QR Method with Shifts).
  10. % Section    11.4,    Eigenvalues of Symmetric Matrices, Page 574
  11. echo on; clc; format long; hold off; clear
  12.  
  13. clc;
  14.  
  15. % HOUSEHOLDER`S  METHOD   followed by the   QR METHOD
  16.  
  17. % Remark. house2.m and qr2.m are used for Algorithm 11.QR
  18.  
  19. % First proceed with Householder`s method.
  20.  
  21. A = [4    2    2    1;
  22.      2   -3    1    5;
  23.      2    1    3    1;
  24.      1    5    1    2];
  25.  
  26. B = house2(A,1);
  27.  
  28. pause % Press any key to continue.
  29.  
  30. clc;
  31. Ms1 = 'The matrix  A  is:';
  32. Ms2 = 'The similar tridiagonal matrix B is:';
  33. clc,disp(' '),disp(Ms1),disp(A),disp(Ms2),disp(B)
  34.  
  35. pause % Press any key to continue.
  36.  
  37. clc;
  38.  
  39. epsilon = 5e-15;
  40.  
  41. D = qr2(B,epsilon,1);
  42.  
  43. pause % Press any key to continue.
  44.  
  45. clc;
  46. Mx1 = 'Implementation of Householder reduction,';
  47. Mx2 = 'followed by the QR method with shifts.';
  48. Mx3 = 'The matrix  A  is:';
  49. Mx4 = 'The similar diagonal matrix is:'
  50. Mx5 = 'The eigenvalues are:';
  51. clc,echo off,diary output,...
  52. disp(' '),disp(Mx1),disp(Mx2),...
  53. disp(' '),disp(Mx3),disp(A),disp(Mx4),...
  54. disp(diag(D)),disp(Mx5),disp(D),diary off,echo on
  55.